﻿using KwaiXiaoDian.Data;
using KwaiXiaoDian.Entity.Common;
using KwaiXiaoDian.Entity.DO;
using KwaiXiaoDian.Entity.VO.GroupLeader;
using KwaiXiaoDian.IDao;
using SSharing.Frameworks.NetCore.Common.Extends;
using SSharing.Frameworks.NetCore.Common.Results;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Linq.Expressions;

namespace KwaiXiaoDian.Dao
{
    /// <summary>
    /// 团长dao
    /// </summary>
    public class GroupLeaderDao : BaseDao<TGroupLeader>, IGroupLeaderDao
    {
        private readonly KwaiXiaoDianDbContext _kwaiXiaoDianDbContext;

        public GroupLeaderDao(KwaiXiaoDianDbContext kwaiXiaoDianDbContext) : base(kwaiXiaoDianDbContext)
        {
            _kwaiXiaoDianDbContext = kwaiXiaoDianDbContext;
        }

        /// <summary>
        /// 获取团长列表
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public IPagingResult<TGroupLeader> GetPagingLeaders(GetPagingLeadersRequest request)
        {
            IPagingResult<TGroupLeader> pagingResult = new PagingResult<TGroupLeader>();

            var query = _kwaiXiaoDianDbContext.TGroupLeader.AsQueryable();

            //查询条件
            if (!request.LeaderId.IsNullOrEmpty())
            {
                var leaderId = request.LeaderId.Trim();
                query = query.Where(p => p.LeaderId == request.LeaderId);
            }
            if (!request.LeaderName.IsNullOrEmpty())
            {
                var name = request.LeaderName.Trim();
                query = query.Where(p => p.Name.Contains(name));
            }
            if (!request.Status.IsNullOrEmpty())
            {
                var status = request.Status;
                query = query.Where(p => p.IsEnabled == status);
            }

            //默认按创建时间倒序
            query = query.OrderByDescending(p => p.CreatedTime);

            //分页
            return query.PagingWithNoLock(request.Page, request.Limit);
        }


    }
}
